package com.spring.sunflower.dialog

import android.content.Context
import android.widget.LinearLayout
import android.widget.TextView
import com.lxj.xpopup.core.CenterPopupView
import com.spring.sunflower.R

/**
 * Created by Kevin on 2021/8/6<br/>
 *
 * Describe:<br/>
 */
class PermissionIntroDialog(
    context: Context,
    var layoutID: Int,
    var listener: OnPermissionIntroClickListener?
) : CenterPopupView(context) {
    private var llContainer: LinearLayout? = null
    override fun getImplLayoutId(): Int {
        return layoutID
    }

    override fun onCreate() {
        super.onCreate()
        llContainer = findViewById<LinearLayout>(R.id.llContainer)
        xListener?.onCreateView()
        val tvOK: TextView = findViewById(R.id.tvOK)
        val tvCancel: TextView = findViewById(R.id.tvCancel)
        tvOK.setOnClickListener {
            listener?.onClickOK()
            dismiss()
        }
        tvCancel.setOnClickListener {
            listener?.onClickCancel()
            dismiss()
        }
        val tvTip: TextView = findViewById(R.id.tv)
        if (listener == null) {
            tvTip.text = "权限申请提示"
        } else {
            tvTip.text = "权限申请说明"
        }
    }

    fun getContainer(): LinearLayout {
        return llContainer!!
    }

    private var xListener: OnCreateViewListener? = null
    fun setOnCreateViewListener(l: OnCreateViewListener) {
        xListener = l
    }

    fun interface OnCreateViewListener {
        fun onCreateView()
    }
}